package com.hoku.registry.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * @author ZHUFEIFEI
 */
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Value("${management.endpoints.web.base-path}")
    private String managementContextPath;
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        //使用security认证，客户端采用http://user:pass@localhost:port/eureka/形式时，必须禁用csrf，
        http.csrf().disable();
        //允许表单登陆
        http.formLogin().permitAll();
        //健康检查相关的允许直接访问
        http.authorizeRequests().antMatchers(managementContextPath+"/**")
                .permitAll();
        http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
    }
}
